#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (int argc, char const* argv[])
{
    char buf[256];
    int ans, i, val, len;

    while (gets(buf)) {
        if (strcmp(buf, "#") == 0) break;

        len = strlen(buf);
        ans = 0;
        for (i = 0; i < len; i++) {
            if (buf[i] == ' ') val = 0;
            else val = buf[i] - 'A' + 1;

            ans += (i+1) * val;
        }
        
        printf("%d\n", ans);
    }

    return 0;
}
